package com.yinsin.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class IdUtils {

	private static String[] chats = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"};
	private static Map<String, IdWorker> IDWORKER_MAP = new ConcurrentHashMap<String, IdWorker>();

	public static synchronized String getUniqueId(int num) {
		if (num > 15) {
			num = 15;
		}
		String key = chats[(int)(Math.random() * chats.length)] + num;
		IdWorker worker = IDWORKER_MAP.get(key);
		if (null == worker) {
			worker = new IdWorker(IDWORKER_MAP.size());
			IDWORKER_MAP.put(key, worker);
		}
		return key + worker.nextId();
	}

}
